package com.cos.m3.web.controller;

import org.springframework.web.bind.annotation.*;

/**
 * @author: COS
 * @time: 2022/6/9 15:30
 * @description:
 * RestController = > @Controller +@ResponseBody
 */
@RestController
@RequestMapping("/rest")
//@CrossOrigin(origins = {"http://localhost:8080/","xxxxxx"})
// ajax 携带cookie 没有经过服务器验证(服务同意),触发同源策略问题,只要设置@CrossOrigin(allowCredentials = "true") 为同意携带信息
@CrossOrigin(allowCredentials = "true")
public class RestDemoController {
    //去差异化
    @RequestMapping(value = "/user", method = RequestMethod.POST,produces = "text/html;charset=utf-8")
    public String add() {
        return "add user";
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public String getUserAll() {
        System.out.println("进入 get all user");
        return "get all user";
    }

    @RequestMapping(value = "/user", method = RequestMethod.PUT)
    public String updateuser() {
        return "update user";
    }
    @RequestMapping(value = "/user/{id}", method = RequestMethod.DELETE)
    public String deluser(@PathVariable Integer id) {
        return "delete user :"+id;
    }

    //@GetMapping("/emp")  ==>@RequestMapping(value = "/user", method = RequestMethod.GET)
//    @PostMapping("/emp") ==>@RequestMapping(value = "/user", method = RequestMethod.POST)
//    @PutMapping("/emp")  ==>@RequestMapping(value = "/user", method = RequestMethod.PUT)
    @DeleteMapping("/emp")  //==>@RequestMapping(value = "/user", method = RequestMethod.DELETE)
    public String addEmp(){
        return "add emp";
    }


}
